//  sudo java --classpath ./test.jar com.torben.test.jhttp2 /home/torben/html 100


package com.torben.test;

import java.net.*;
import java.io.*;
import java.util.*;

public class jhttp2 extends Thread {

  Socket theConnection;
  static File docroot;
  static String indexfile = "index.html";
  
  public jhttp2(Socket s) {
    theConnection = s;
  }

  public static void main(String[] args) {

    int thePort;
    ServerSocket ss;

    // get the Document root
    try {
      docroot = new File(args[0]);
    }
    catch (Exception e) {
      docroot = new File(".");
    }
    
    // set the port to listen on
    try {
      thePort = Integer.parseInt(args[1]);
      if (thePort < 0 || thePort > 65535) thePort = 80;
    }  
    catch (Exception e) {
      thePort = 80;
    }  
                
    try {
      ss = new ServerSocket(thePort);
      System.out.println("Accepting connections on port " 
        + ss.getLocalPort());
      System.out.println("Document Root:" + docroot);
      while (true) {
        jhttp2 j = new jhttp2(ss.accept());
        j.start();
      }
    }
    catch (IOException e) {
      System.err.println("Server aborted prematurely");
      System.err.println(e);
    }
  
  }

  public void run() {
  
    String method;
    String file="";
    String ct;
    String version = "";
    File theFile;
  
    try {
      PrintStream os = new PrintStream(theConnection.getOutputStream());
      DataInputStream is = new DataInputStream(theConnection.getInputStream());
      String get = is.readLine();
      
      System.out.println("modtaget data : " + get );
      
    
          
          Date now2 = new Date();
          
          
          os.println("Tag den her : " +  now2 + " data " + get );
          os.close();
     
      theConnection.close();
    }
    catch (IOException e) {
    }
    
  }
}

  